﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using static SimpleTool.SerialTool.SerialControl.CommandSectionModel;

namespace SimpleTool.SerialTool.SerialControl
{
    /// <summary>
    /// Command.xaml //      /// </summary>
    public partial class SerialCommandUI : UserControl
    {
        public readonly ILogger Logger = Log.ForContext<SerialCommandUI>();

        public SerialCommandUI()
        {
            InitializeComponent();
            this.Loaded += LoadFinish;
        }

        private void LoadFinish(object sender, RoutedEventArgs e)
        {
            App MyApp = (App)Application.Current;
            SerialViewModel ViewModel = MyApp.ServiceProvider.GetRequiredService<SerialViewModel>();
            if (ViewModel == null)
            {
                Logger.Error("config viewmodel service is null");
            }
            else
            {
                this.DataContext = ViewModel;
            }
            this.Unloaded -= LoadFinish;
        }
    }
}
